//
//  TagViewDemoController.m
//  JackToolsBox
//
//  Created by Jack Xue on 2019/12/11.
//  Copyright © 2019 Jack Xue. All rights reserved.
//

#import "TagViewDemoController.h"
//drawRect
#import "JKTagView.h"       //使用drawRect实现的tagview
#import "JKTestItem.h"
//layoutSubview
#import "JKTagLabView.h"    //使用layoutSubview实现的tagview
#import "JKSonTagPart.h"    //自定义JKTagPart

@interface TagViewDemoController ()<TagSelectedDelegate,JKTagLabViewDateSource,JKTagLabViewDelegate>

@end

@implementation TagViewDemoController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    if (self.isDrawRect) {
        //使用drawrect实现的tagview
        JKTagView *tempView = [[JKTagView alloc]initWithFrame:CGRectMake(50, 100, 200, 0)];
        tempView.delegate = self;
        NSMutableArray *dataArray = [NSMutableArray arrayWithCapacity:0];
        NSArray *tempArray = @[@"123",@"445566",@"hhhdjff",@"fasdfadsfasdf",@"909",@"6789",@"www.baidu.com"];
        for (NSString *string in tempArray) {
            JKTestItem *item = [JKTestItem new];
            item.Id_number = [NSString stringWithFormat:@"id-%ld",(long)[tempArray indexOfObject:string]];
            item.titleString = string;
            [dataArray addObject:item];
        }
        [tempView setDataSourceArray:dataArray];
        [self.view addSubview:tempView];
    }else{
        //使用layoutSubview实现的tagview
        JKTagLabView *tagLabel = [[JKTagLabView alloc]initWithFrame:CGRectMake(50, 100, 200, 100)];
        tagLabel.dataSource = self;
        tagLabel.delegate = self;
        [self.view addSubview:tagLabel];
    }
}

#pragma mark - TagSelectedDelegate
-(void)didSelectedTagWithIndex:(NSInteger)index item:(nonnull JkTagItem *)model{
    JKTestItem *item = (JKTestItem*)model;
    NSLog(@"点击了%ld---%@---自定义属性%@",(long)index,item.titleString,item.Id_number);
}

#pragma mark - JKTagLabViewDateSource
-(JKTagPart*)tagCellAtIndex:(NSInteger)index{
    NSArray *dataArray = @[@"1111",@"2222222",@"333333",@"4444444",@"55555",@"6666666666666"];
    JKSonTagPart *cell = [[JKSonTagPart alloc] initWithFrame:CGRectZero];
    cell.infoString = dataArray[index];
    cell.fontSize = 15;
    cell.enableBorder = NO;
    cell.backgroundColor = [UIColor yellowColor];
    return cell;
}

-(NSInteger)numberOfItemsForTagCell{
    return 6;
}

#pragma mark - JKTagLabViewDelegate
-(void)didSelectedLabelTagWithIndex:(NSInteger)index{
    NSLog(@"点击%ld",(long)index);
}



@end
